﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace SharePointCustomizer
{
    public partial class AddCss : Form
    {
        
        public string projectPath;
        /// <summary>
        /// 
        /// </summary>
        public AddCss()
        {
            InitializeComponent();
        }
        /// <summary>
        /// btnCancel Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        /// <summary>
        /// btnSave Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            CreateNewCSS();
        }
        /// <summary>
        /// Create New CSS
        /// </summary>
        private void CreateNewCSS()
        {
            try
            {
                if (txtFileName.Text.Trim() != "")
                {
                    MainForm mForm = (MainForm)this.Owner;

                    string path = projectPath + "\\css";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    path += "\\" + txtFileName.Text;
                    StreamWriter StW = File.CreateText(path);
                    StW.Close();
                    mForm.isNew = true;
                    ComboBox cmbStyle = (ComboBox)Owner.Controls["comboBoxStyle"];
                    cmbStyle.Items.Add(path);
                    cmbStyle.SelectedIndex = cmbStyle.Items.Count - 1;
                                       
                    mForm.ApplyCss(path);

                    this.Owner.Activate();
                    this.Dispose();
                }
                else
                {
                    MessageBox.Show("You must selelct a folder", "SharePoint Customizer");
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
         }
    }
}
